from flask import request, Blueprint, json
from services import service_admin as service
from util import mapping

admin_blue = Blueprint('admin', __name__)


# 管理员
@admin_blue.route('/admin', methods=['get'])
def getAdmin():
    data = service.getAll()
    return data


@admin_blue.route('/admin/<id>', methods=['get'])
def getAdminById(id):
    data = service.getById(id)
    return data


@admin_blue.route('/admin', methods=['put'])
def updateAdmin():
    rq_data = request.get_json()
    print(rq_data)
    rq_data = mapping.dictToAdminDic(rq_data)
    data = service.update(rq_data)
    return data


@admin_blue.route('/admin', methods=['post'])
def addAdmin():
    request_data = request.get_json()  # 格式 {'id': 169, 'name': '逄无敌', 'mobile': '18680343705', 'address': '536', 'email': '54@qq.com', 'gender': '女', 'age': '542'}
    data = service.add(request_data)
    return data


@admin_blue.route('/admin/<ID>', methods=['delete'])
def deleteAdmin(ID):
    data = service.deleteByID(ID)
    return data


@admin_blue.route('/login', methods=['post'])
def login():
    request_data = request.get_json()
    print(request_data)
    data = service.login(request_data)
    return data




